import { rule } from "@/util/validateRules";
const validatorCnapsLen = (rule, value, callback) => {
  let reg = /^[0-9]+[a-zA-Z]$/;
  if (!reg.test(value) || value.length <= 1) {
    callback(new Error('长度必须大于等于1且最后一个字符必须为字母！'))
  } else {
    callback()
  }
}
const  integerRule = (rule, value, callback) => {
  let reg = /^[0-9]\d*|0$/
  if (value && (!(reg).test(value))) {
    callback(new Error('只允许输入非负整数'))
  } else {
    callback()
  }
}
export const addList = {
  more: [{
    label: '报文',
    value: 'policy',
    addType: 'more'
  }, {
    label: '报文字段',
    value: 'field',
    addType: 'single'
  },{
    label: '报文域',
    value: 'struct',
    addType: 'more'
  }],
  single: [{
    label: '报文',
    value: 'policy',
    addType: 'more'
  }]
}

export const dictType = [
  {
    label: '报文',
    value: 'policy',
  },
  {
    label: '报文字段',
    value: 'field',
  },
  {
    label: '报文域',
    value: 'struct',
  }
]

export const formMap = {
  policy: [{
    label: '报文类型',
    key: 'type',
    type: 'select',
    dicDataKey: 'reportList',
    dicOptionKey: 'type',
    rules: [{ required: true, message: '请选择报文类型', trigger: 'change' }]
  }, {
    label: '描述信息',
    key: 'desc',
    maxlength: 50,
    showWordLimit: true,
  }],

  field: [{
    label: '字段名称',
    key: 'name',
    maxlength: 50,
    showWordLimit: true,
    rules: [{ required: true, message: '字段名称不能为空', trigger: 'blur' }]
  }, {
    label: '描述信息',
    key: 'desc',
    maxlength: 50,
    showWordLimit: true,
  }],

  struct: [{
    label: '记录集名称',
    key: 'name',
    maxlength: 50,
    showWordLimit: true,
    rules: [{ required: true, message: '记录名称不能为空', trigger: 'blur' }]
  }, {
    label: '描述信息',
    key: 'desc',
    maxlength: 50,
    showWordLimit: true,
  }]
}


export const changeForm = {
  pack: {
    policy:{
      fixed: [
        {
          label: '填充类型',
          type: 'select',
          key: 'fillType',
          dicDataKey: 'fillTypeList',
          defaultVal: 'char',
        },
        {
          label: '填充字符',
          key: 'fillChar',
          maxlength: 50,
          showWordLimit: true,
        },
        {
          label: '填充方向',
          type: 'select',
          key: 'fillLocation',
          dicDataKey: 'fillLocationList',
          defaultVal: 'left',
        },
      ],
      delim: [
        {
          label: '分隔符字符',
          key: 'delimChar',
          maxlength: 50,
          showWordLimit: true,
          rules: [{ required: true, message: '分隔符字符不能为空', trigger: 'blur' }]
        },
        {
          label: '需要转义的字符串',
          key: 'escapeChar',
          maxlength: 50,
          showWordLimit: true,
        },
        {
          label: '转义中文特殊字符',
          type: 'select',
          key: 'escapeZh',
          dicDataKey: 'whetherList',
          defaultVal: 'true',
        },
        {
          label: '转义字符',
          key: 'escapePrefix',
          maxlength: 50,
          showWordLimit: true,
        },
      ],
      xml: [
        {
          label: '显示序言',
          type: 'select',
          key: 'prologue',
          dicDataKey: 'whetherList',
          defaultVal: 'true',
        },
        {
          label: '是否产生空节点',
          type: 'select',
          key: 'genEmptyNode',
          dicDataKey: 'whetherList',
          defaultVal: 'true',
        },
        {
          label: 'XML输出格式',
          type: 'select',
          key: 'prettyprint',
          dicDataKey: 'xmlList',
          defaultVal: ' ',
        },
        {
          label: '缩进填充字符串',
          key: 'ns_',
          maxlength: 50,
          showWordLimit: true,
        },
        {
          label: '编码方式',
          type: 'select',
          key: 'encoding',
          dicDataKey: 'charsetList',
          defaultVal: 'UTF-8',
        },
      ],
      cnaps1: [
        // {
        //   label: '默认名称空间',
        //   key: 'ns_def',
        //   maxlength: 50,
        //   showWordLimit: true,
        // },
        // {
        //   label: '名称空间',
        //   key: 'ns',
        //   maxlength: 50,
        //   showWordLimit: true,
        // },
      ],
      cnaps2: [
        {
          label: '默认名称空间',
          key: 'ns_def',
          maxlength: 50,
          showWordLimit: true,
        },
        {
          label: '名称空间',
          key: 'ns',
          maxlength: 50,
          showWordLimit: true,
        },
      ],
      http: [
        {
          label: '编码方式',
          type: 'select',
          key: 'encoding',
          dicDataKey: 'charsetList',
          defaultVal: 'UTF-8',
          rules: [{ required: true, message: '请选择编码方式', trigger: 'change' }]
        },
      ],
      json: [
        {
          label: '自动适配',
          type: 'select',
          key: 'automap',
          dicDataKey: 'whetherList',
          defaultVal: 'false',
        },
      ],
      iso8583: [
        {
          label: '位图格式',
          type: 'select',
          key: 'bitmapencoding',
          dicDataKey: 'bitmapList',
          defaultVal: 'bin',
        },
      ]
    },
    field:{
      fixed: [
        {
          label: '字段长度',
          key: 'len',
          maxlength: 50,
          showWordLimit: true,
          rules: [{required: true, message: '请输入字段长度', trigger: 'blur'},{ validator: rule.validatorNumber, trigger: 'blur'}]
        },
        {
          label: '填充字符',
          key: 'fillChar',
          maxlength: 50,
          showWordLimit: true,
        },
        {
          label: '填充类型',
          type: 'select',
          key: 'fillType',
          dicDataKey: 'fillTypeList',
          defaultVal: 'char',
        },
        {
          label: '填充方向',
          type: 'select',
          key: 'fillLocation',
          dicDataKey: 'fillLocationList',
          defaultVal: 'left',
        },
        {
          label: '缺省值',
          key: 'defVal',
          maxlength: 50,
          showWordLimit: true,
        },
      ],
      delim: [
        {
          label: '分隔符字符',
          key: 'delimChar',
          maxlength: 50,
          showWordLimit: true,
          rules: [{ required: true, message: '分隔符字符不能为空', trigger: 'blur' }]
        },
        {
          label: '需要转义的字符串',
          key: 'escapeChar',
          maxlength: 50,
          showWordLimit: true,
        },
        {
          label: '转义中文特殊字符',
          type: 'select',
          key: 'escapeZh',
          dicDataKey: 'whetherList',
          defaultVal: 'true',
        },
        {
          label: '转义字符',
          key: 'escapePrefix',
          maxlength: 50,
          showWordLimit: true,
        },
        {
          label: '缺省值',
          key: 'defVal',
          maxlength: 50,
          showWordLimit: true,
        },
      ],
      xml: [
        {
          label: '字段值',
          key: 'value',
          maxlength: 50,
          showWordLimit: true,
        },
        {
          label: 'xpath',
          key: 'xpath',
          maxlength: 200,
          showWordLimit: true,
          rules: [{ required: true, message: 'xpath不能为空', trigger: 'blur' }]
        },
      ],
      cnaps1: [
        {
          label: 'tag值',
          key: 'tag',
          maxlength: 50,
          showWordLimit: true,
          rules: [{required: true, message: '请输入tag值', trigger: 'blur'}]
        },
        {
          label: '长度',
          key: 'len',
          maxlength: 50,
          showWordLimit: true,
          rules: [{required: true, message: '请输入字段长度', trigger: 'blur'},{ validator: validatorCnapsLen, trigger: 'blur'}]
        },
        {
          label: '缺省值',
          key: 'defVal',
          maxlength: 50,
          showWordLimit: true,
        },
      ],
      cnaps2: [
        {
          label: '字段值',
          key: 'value',
          maxlength: 50,
          showWordLimit: true,
        },
        {
          label: 'xpath',
          key: 'xpath',
          maxlength: 200,
          showWordLimit: true,
          rules: [{ required: true, message: 'xpath不能为空', trigger: 'blur' }]
        },
        {
          label: 'tag值',
          key: 'tag',
          maxlength: 50,
          showWordLimit: true,
        },

      ],
      http: [
        {
          label: '参数名称',
          key: 'tag',
          maxlength: 50,
          showWordLimit: true,
          rules: [{ required: true, message: '参数名称不能为空', trigger: 'blur' }]
        },
      ],
      json: [
        {
          label: 'path',
          key: 'path',
          maxlength: 200,
          showWordLimit: true,
          rules: [{ required: true, message: 'path不能为空', trigger: 'blur' }]
        },
        {
          label: '缺省值',
          key: 'defVal',
          maxlength: 50,
          showWordLimit: true,
        },
      ],
      iso8583: [
        {
          label: '字段序号',
          key: 'tag',
          maxlength: 50,
          showWordLimit: true,
          rules: [{required: true, message: '请输入字段序号', trigger: 'blur'},{ validator: integerRule, trigger: 'blur'}]
        },
      ]
    },
    struct: {
      xml: [
        {
          label: 'xpath',
          key: 'xpath',
          maxlength: 200,
          showWordLimit: true,
          rules: [{ required: true, message: 'xpath不能为空', trigger: 'blur' }]
        },
      ],
      cnaps1: [
        {
          label: '报文域前缀',
          key: 'prefix',
          maxlength: 200,
          showWordLimit: true,
          rules: [{ required: true, message: '报文域前缀不能为空', trigger: 'change' }]
        },
        {
          label: '报文域后缀',
          key: 'suffix',
          maxlength: 200,
          showWordLimit: true,
          rules: [{ required: true, message: '报文域后缀不能为空', trigger: 'change' }]
        },
        {
          label: '密押要素',
          key: 'signature',
          type: 'select',
          dicDataKey: 'whetherList',
          defaultVal: 'true',
        }
      ],
      cnaps2: [
        {
          label: 'xpath',
          key: 'xpath',
          maxlength: 200,
          showWordLimit: true,
          rules: [{ required: true, message: 'xpath不能为空', trigger: 'blur' }]
        },
      ],
      json: [
        {
          label: 'path',
          key: 'path',
          maxlength: 200,
          showWordLimit: true,
          rules: [{ required: true, message: 'path不能为空', trigger: 'blur' }]
        },
      ],
    }
  },
  unpack: {
    policy:{
      fixed: [
        {
          label: '填充类型',
          type: 'select',
          key: 'fillType',
          dicDataKey: 'fillTypeList',
          defaultVal: 'char',
        },
        {
          label: '填充字符',
          key: 'fillChar',
          maxlength: 50,
          showWordLimit: true,
        },
        {
          label: '填充方向',
          type: 'select',
          key: 'fillLocation',
          dicDataKey: 'fillLocationList',
          defaultVal: 'left',
        },
      ],
      delim: [
        {
          label: '分隔符字符',
          key: 'delimChar',
          maxlength: 50,
          showWordLimit: true,
          rules: [{ required: true, message: '分隔符字符不能为空', trigger: 'blur' }]
        },
        {
          label: '需要转义的字符串',
          key: 'escapeChar',
          maxlength: 50,
          showWordLimit: true,
        },
        {
          label: '转义中文特殊字符',
          type: 'select',
          key: 'escapeZh',
          dicDataKey: 'whetherList',
          defaultVal: 'true',
        },
        {
          label: '转义字符',
          key: 'escapePrefix',
          maxlength: 50,
          showWordLimit: true,
        },
      ],
      xml: [
        {
          label: '编码方式',
          type: 'select',
          key: 'encoding',
          dicDataKey: 'charsetList',
          defaultVal: 'UTF-8',
        },
      ],
      cnaps1: [
        // {
        //   label: '默认名称空间',
        //   key: 'ns_def'
        // },
        // {
        //   label: '名称空间',
        //   key: 'ns'
        // },
      ],
      cnaps2: [
        {
          label: '默认名称空间',
          key: 'ns_def',
          maxlength: 50,
          showWordLimit: true,
        },
        {
          label: '名称空间',
          key: 'ns',
          maxlength: 50,
          showWordLimit: true,
        },
      ],
      http: [
        {
          label: '编码方式',
          type: 'select',
          key: 'encoding',
          dicDataKey: 'charsetList',
          defaultVal: 'UTF-8',
          rules: [{ required: true, message: '请选择编码方式', trigger: 'change' }]
        },
      ],
      json: [
        {
          label: '自动适配',
          type: 'select',
          key: 'automap',
          dicDataKey: 'whetherList',
          defaultVal: 'true',
        },
      ],
      iso8583: [
        {
          label: '位图格式',
          type: 'select',
          key: 'bitmapencoding',
          dicDataKey: 'bitmapList',
          defaultVal: 'bin',
        },
      ]
    },
    field:{
      fixed: [
        {
          label: '字段长度',
          key: 'len',
          maxlength: 50,
          showWordLimit: true,
          rules: [{required: true, message: '请输入字段长度', trigger: 'blur'},{ validator: rule.validatorNumber, trigger: 'blur'}]
        },
        {
          label: '偏移量',
          key: 'offset',
          maxlength: 50,
          showWordLimit: true,
        },
        {
          label: '填充字符',
          key: 'fillChar',
          maxlength: 50,
          showWordLimit: true,
        },
        {
          label: '填充类型',
          type: 'select',
          key: 'fillType',
          dicDataKey: 'fillTypeList',
          defaultVal: 'char',
        },
        {
          label: '填充方向',
          type: 'select',
          key: 'fillLocation',
          dicDataKey: 'fillLocationList',
          defaultVal: 'left',
        },
        {
          label: '缺省值',
          key: 'defVal',
          maxlength: 50,
          showWordLimit: true,
        },
      ],
      delim: [
        {
          label: '分隔符字符',
          key: 'delimChar',
          maxlength: 50,
          showWordLimit: true,
          rules: [{ required: true, message: '分隔符字符不能为空', trigger: 'blur' }]
        },
        {
          label: '需要转义的字符串',
          key: 'escapeChar',
          maxlength: 50,
          showWordLimit: true,
        },
        {
          label: '转义中文特殊字符',
          type: 'select',
          key: 'escapeZh',
          dicDataKey: 'whetherList',
          defaultVal: 'true',
        },
        {
          label: '转义字符',
          key: 'escapePrefix',
          maxlength: 50,
          showWordLimit: true,
        },
        {
          label: '跳过字段数',
          key: 'skipped',
          maxlength: 50,
          showWordLimit: true,
        },
        {
          label: '缺省值',
          key: 'defVal',
          maxlength: 50,
          showWordLimit: true,
        },
      ],
      xml: [
        {
          label: '字段值',
          key: 'value',
          maxlength: 50,
          showWordLimit: true,
        },
        {
          label: 'xpath',
          key: 'xpath',
          maxlength: 200,
          showWordLimit: true,
          rules: [{ required: true, message: 'xpath不能为空', trigger: 'blur' }]
        },
      ],
      cnaps1: [
        {
          label: 'tag值',
          key: 'tag',
          maxlength: 50,
          showWordLimit: true,
          rules: [{required: true, message: '请输入tag值', trigger: 'blur'}]
        },
        {
          label: '长度',
          key: 'len',
          maxlength: 50,
          showWordLimit: true,
          rules: [{required: true, message: '请输入字段长度', trigger: 'blur'},{ validator: validatorCnapsLen, trigger: 'blur'}]
        },
        {
          label: '缺省值',
          key: 'defVal',
          maxlength: 50,
          showWordLimit: true,
        },
      ],
      cnaps2: [
        {
          label: '字段值',
          key: 'value',
          maxlength: 50,
          showWordLimit: true,
        },
        {
          label: 'xpath',
          key: 'xpath',
          maxlength: 200,
          showWordLimit: true,
          rules: [{ required: true, message: 'xpath不能为空', trigger: 'blur' }]
        },
        {
          label: 'tag值',
          key: 'tag',
          maxlength: 50,
          showWordLimit: true,
        },

      ],
      http: [
        {
          label: '参数名称',
          key: 'tag',
          maxlength: 50,
          showWordLimit: true,
          rules: [{ required: true, message: '参数名称不能为空', trigger: 'blur' }]
        },
      ],
      json: [
        {
          label: 'path',
          key: 'path',
          maxlength: 200,
          showWordLimit: true,
          rules: [{ required: true, message: 'path不能为空', trigger: 'blur' }]
        },
        {
          label: '缺省值',
          key: 'defVal',
          maxlength: 50,
          showWordLimit: true,
        },
      ],
      iso8583: [
        {
          label: '字段序号',
          key: 'tag',
          maxlength: 50,
          showWordLimit: true,
          rules: [{required: true, message: '请输入字段序号', trigger: 'blur'},{ validator: integerRule, trigger: 'blur'}]
        },
      ]
    },
    struct: {
      xml: [
        {
          label: 'xpath',
          key: 'xpath',
          maxlength: 200,
          showWordLimit: true,
          rules: [{ required: true, message: 'xpath不能为空', trigger: 'blur' }]
        },
      ],
      cnaps1: [
        {
          label: '报文域前缀',
          key: 'prefix',
          maxlength: 200,
          showWordLimit: true,
          rules: [{ required: true, message: '报文域前缀不能为空', trigger: 'change' }]
        },
        {
          label: '报文域后缀',
          key: 'suffix',
          maxlength: 200,
          showWordLimit: true,
          rules: [{ required: true, message: '报文域后缀不能为空', trigger: 'change' }]
        },
        {
          label: '密押要素',
          key: 'signature',
          type: 'select',
          dicDataKey: 'whetherList',
          defaultVal: 'true',
        }
      ],
      cnaps2: [
        {
          label: 'xpath',
          key: 'xpath',
          maxlength: 200,
          showWordLimit: true,
          rules: [{ required: true, message: 'xpath不能为空', trigger: 'blur' }]
        },
      ],
      json: [
        {
          label: 'path',
          key: 'path',
          maxlength: 200,
          showWordLimit: true,
          rules: [{ required: true, message: 'path不能为空', trigger: 'blur' }]
        },
      ],
    },
  }

}
